<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">

<head>
    <meta charset="utf-8">
    <title>
        撤销
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
</head>
<style>

</style>

<body>
<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="add">

        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <span style="font-weight:bold">撤销配件</span>
                <table class="layui-table" >
                    <thead>
                        <tr>
                            <th>物料号</th>
                            <th>配件名称</th>
                            <th>规格型号</th>
                            <th>入库数量</th>
                            <th>物料批次</th>
                            <th>配件单价</th>
                            <th>配件总价</th>
                            <th>可撤销数量</th>
                            <th>撤销数量<span style="color: red;">*</span></th>
                            <th>撤销备注</th>
                        </tr>
                    </thead>
                    <tbody id="ttt">
                        <tr v-for='(item,index) in rebackPartArr'>
                            <td>
                                {{item.partsNum}}
                            </td>
                            <td>
                                {{item.partsName}}
                            </td>
                            <td>
                                {{item.specification}}
                            </td>
                            <td>
                                {{item.partsCount}}
                            </td>
                            <td>
                                {{item.partsMark}}
                            </td>
                            <td>
                                {{item.partsOneprice}}
                            </td>
                            <td>
                                {{item.partsAllprice}}
                            </td>
                            <td>
                                {{item.mayNumber}}
                            </td>
                            <td>
                                <input  autocomplete="off"  type="number" class="layui-input" id="chexiaoNum" onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');" placeholder="撤销数量" v-model='item.chexiaoNum'>
<!--                                <input  autocomplete="off"  type="text" class="layui-input" placeholder="撤销数量" v-model='rebackPart.chexiaoNum'>-->
                            </td>
                            <td>
                                <input  autocomplete="off"  type="text" class="layui-input" placeholder="撤销备注" v-model='item.chexiaoMemo'>
                            </td>

                        </tr>
                    </tbody>
                </table>
<!--                <span style="color: red">注意：填写的数量为正数，最多三位小数。填0或留空，认为无需撤销。</span>-->
                <br>
                <span style="font-weight:bold">备注信息</span>
                <div class="layui-form-item layui-form-text" style="margin-top: 8px;">
                    <div class="layui-input-block">
                        <textarea name="remake" placeholder="备注信息" class="layui-textarea"></textarea>
                    </div>
                </div>

                <div style="text-align: center" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                        确定
                    </button>
                </div>
            </div>


        </div>

    </form>
</div>
<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var recordId = getQueryVariable("recordId");

    layui.use(['table', 'laydate', 'form', 'layer'],
        function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            var form = layui.form;
            var layer = layui.layer;
            var table = layui.table;


        });


    const vm = new Vue({
        el: "#app",
        data: {
            rebackPartArr:[],

        },
        created() {
            this.getRepealPartsMsg();
        },
        computed: {
        },
        methods: {
            getRepealPartsMsg: function() {
                var that = this;
                let request = {
                    url: 'kf/partsJoinWarehouse/getRepealParts',
                    data: {
                        userId: $userId,
                        id:recordId
                    },
                    method: "get"
                }
                sendRequest(request, (res) => {
                    if (res.code == 0) {
                        backData = res.data;
                        for (var i=0;i<backData.length;i++){
                            backData[i].chexiaoNum = '';
                            backData[i].chexiaoMemo = '';
                        }
                        that.rebackPartArr = backData;
                    } else {
                        layer.alert(data.msg, {
                            icon: 5
                        })
                    }

                })
            },

        },
        mounted() {
            var that = this;
            layui.use(['table', 'form', 'upload','layer'], function() {
                var table = layui.table;
                var form = layui.form;
                var upload = layui.upload;

                form.on('submit(sub)', function (data) {
                    var val = {};
                    val.userId = $userId;
                    val.id = recordId;
                    val.remake = data.field.remake;
                    var addArr = [];

                    var emptyChexiaoNum = 0;
                    for(var i = 0; i < that.rebackPartArr.length; i++) {

                        if (parseInt(that.rebackPartArr[i].chexiaoNum) > parseInt(that.rebackPartArr[i].number)) {
                            layer.msg("=> 【撤销数量】 不能大于 【可撤销数】，请重新核对->撤销数量！", {
                                icon: 7
                            });
                            return false;
                        }
                        if (that.rebackPartArr[i].chexiaoNum == '') {
                            emptyChexiaoNum += 1;
                        }
                        var rebackPartJson = {};

                        rebackPartJson.partsMsgId = that.rebackPartArr[i].partsMsgId;
                        rebackPartJson.repealNumber = that.rebackPartArr[i].chexiaoNum;
                        rebackPartJson.repealRemark = that.rebackPartArr[i].chexiaoMemo;
                        addArr.push(rebackPartJson);
                    }
                    val.list =JSON.stringify(addArr);

                    if (emptyChexiaoNum === that.rebackPartArr.length) {
                        layer.msg("请至少填写一条撤销数量！", {
                            icon: 7
                        });
                        return false;
                    }
                    let request = {
                        url: 'kf/partsJoinWarehouse/repealJoin',
                        data: val,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.location.reload();

                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
            });

            });
        }


    });

</script>

</body>

</html>
